package javaeSE;
/*
  抽象类的匿名子类  与匿名对象
 */
public class Anonymous {
	
	public static void main(String[] args) {

		Anonymous.method(new Student());//匿名对象
		
		Worker worker = new Worker();
		Anonymous.method1(worker);//非匿名的类非匿名的对象

		Anonymous.method1(new Worker());//非匿名的类匿名的对象
		
		System.out.println("*********匿名类***********");
		
		//创建了一匿名子类的对象：p   右侧本质是匿名类
		Persons p = new Persons(){

			@Override
			public void eat() {
				System.out.println("匿名吃东西");
			}

			@Override
			public void breath() {
				System.out.println("匿名好好呼吸");
			}
			
		};
		//PersonTest.method1(p);可以这样写
		method1(p);
		System.out.println("********匿名子类的匿名对象************");
		//创建匿名子类的匿名对象
		method1(new Persons(){
			@Override
			public void eat() {
				System.out.println("匿名子类的匿名对象吃好吃东西");
			}

			@Override
			public void breath() {
				System.out.println("匿名子类的匿名对象好好呼吸新鲜空气");
			}
		});
	}
	
	
	public static void method1(Persons p){
		p.eat();
		p.breath();
		System.out.println("method1");
	}
	
	public static void method(Student s){
		System.out.println("method");
	}
}

class Worker extends Persons{

	@Override
	public void eat() {
		System.out.println("Worker吃");
	}

	@Override
	public void breath() {
		System.out.println("Worker呼");
	}
	
}
